﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 算法基本功.算法._0_数组._1_双指针.左右指针.二分搜索
{
    internal class 经典新手杀手两数之和
    {
        public int[] TwoSum(int[] numbers, int target)
        {
            if (numbers.Length == 0)
            {
                return null;
            }
            int left = 0,right = numbers.Length -1 ;
            while (left < right)
            {
                int sum = numbers[left] + numbers[right];
                if (sum == target)
                {
                    return new int[] { left + 1, right + 1 };
                }
                else if (sum > target)
                    right--;
                else if (sum < target)
                    left++;
            }
            return null;
        }
    }
}
